﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/report/intelligent.css" rel="stylesheet" />
<style type="text/css">
.system-box .right-side{width: 100%;}
.inmodal .modal-body{padding: 10px;}
@media (min-width: 768px) {
	.modal-dialog {
		width: 1080px;
		margin: 30px auto;
	}
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
<div class="system-box">
	<div class="right-side">
		<div class="btns-container">		
			<div class="modal inmodal" id="auxiliary" tabindex="-1" role="dialog" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content animated fadeIn">
			            <div class="modal-header">
			            	<span class="editTitle">补货辅助信息</span>
			                <button type="button" class="close" data-dismiss="modal">
			                	<span aria-hidden="true">&times;</span>
			                	<span class="sr-only">关闭</span>
			            	</button>
			            </div>
			        	<div class="modal-body">
			        		<div style="width: 1060px; height: 360px; overflow: auto; margin: 0 auto;">
			        			<table id="auxiliaryTable">
				            		<thead>
				            			<tr>
				            				<th>店铺</th>
				            				<th>货号</th>
				            				<th>尺码</th>
				            				<th>累计销售</th>
				            				<th>累计调入</th>
				            				<th>周销售</th>
				            				<th>周调入</th>
				            				<th>上市日期</th>
				            				<th>上市天数</th>
				            				<th>日均售罄率</th>
				            				<th>畅滞销状态</th>
				            				<th>区间补货系数</th>
				            				<th>是否核心码</th>
				            				<th>陈列量</th>
				            				<th>理想水位</th>
				            				<th>目标水位</th>
				            				<th>补货需求</th>
				            			</tr>
				            		</thead>
				            		<tbody id="auxiliaryList"></tbody>
				            	</table>
			        		</div>
			        	</div>
					</div>
				</div>
			</div>
		</div>
		<div class="condition-container">
			<div class="left-condition">
				<div class="condition-title">查询条件</div>
				<div class="condition">
					<label>发货仓库</label>
					<select class="form-control input-w110" id="serarch-warehouse">
						<option value="">请选择</option>
					</select>
					<label>　　省份</label>
					<select class="form-control input-w110" id="serarch-province">
						<option value="">请选择</option>
					</select>
					<label>　　城市</label>
					<select class="form-control input-w110" id="serarch-city">
						<option value="">请选择</option>
					</select>
					<label>　　店铺</label>
					<input type="text" class="form-control input-w110" id="search-store" />
				</div>
				<div class="condition">
					<label>货品类别</label>
					<select class="form-control input-w110" id="serarch-type">
						<option value="">全部</option>
					</select>
					
					<label>货品年份</label>
					<select class="form-control input-w110" id="serarch-year">
						<option value="">全部</option>
					</select>
					<label>货品季节</label>
					<select class="form-control input-w110" id="serarch-season">
						<option value="">全部</option>
					</select>
					<label>店铺等级</label>
					<select class="form-control input-w110" id="serarch-level">
						<option value="">全部</option>
					</select>
				</div>
				<div class="condition">
					<label>货品款型</label>
					<select class="form-control input-w110" id="serarch-style">
						<option value="">全部</option>
					</select>
					<label>补货筛选</label>
					<select class="form-control input-w110" id="serarch-screen">
						<option value="-1">全部</option>
						<option value="0">补货需求</option>
						<option value="1" selected="selected">补货结果</option>
					</select>
                    <label>　　货号</label>
					<input type="text" class="form-control input-w288" id="search-artnum" />
				</div>
			</div>
			<div class="right-condition">
				<div class="condition-title">批量维护补货量</div>
				<div class="condition">
					<label>系数</label>
					<input type="number" class="form-control coefficient" />
					<button type="button" class="btn btn-primary" id="application">应用</button>
				</div>
				<table id="batchTable">
					<thead></thead>
					<tbody id="batchList"></tbody>
				</table>
			</div>
			<div class="cb"></div>
		</div>
		
		<div class="cb" style="overflow: hidden; height: 77px; border-top: 1px solid #999;">
			<div class="leftPart">
				<table class="leftTable leftTableTitle">
					<thead></thead>
				</table>
			</div>
			<div class="rightPart rightTitleScroll">
				<table class="rightTable">
					<thead></thead>
				</table>
			</div>
		</div>
		
		<div class="cb">
			<div class="leftPart leftScroll" style="overflow-y: hidden;">
				<table class="leftTable">
					<tbody id="leftList"></tbody>
				</table>
			</div>
			<div class="rightPart rightScroll">
				<table class="rightTable">
					<tbody id="rightList"></tbody>
				</table>
			</div>
		</div>
			
		<div class="pageControl"></div>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script src="../assets/js/framework.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script>
$(document).ready(function(){
	$('.navbar-minimalize i', window.parent.document).click();
	//计算表格高度
	var sUserAgent = navigator.userAgent.toLowerCase();
	var changeTableHeight = function(){
		if(sUserAgent.indexOf('chrome') > -1){
			$('.leftScroll').css({height: ($('.right-side').height() - $('.condition-container').outerHeight() - 146) + 'px'});
			$('.rightScroll').css({height: ($('.leftScroll').height() + 6) + 'px'});
			$('.rightScroll').css({width: ($('.rightTitleScroll').width() + 6) + 'px'});
		}else{
			$('.leftScroll').css({height: ($('.right-side').height() - $('.condition-container').outerHeight() - 160) + 'px'});
			$('.rightScroll').css({height: ($('.leftScroll').height() + 17) + 'px'});
			$('.rightScroll').css({width: ($('.rightTitleScroll').width() + 17) + 'px'});
		}
	}
	changeTableHeight();
	$(window).resize(function(){
		changeTableHeight();
	})
		
	//右表格滚动事件
	$('.rightScroll').scroll(function(){
		$('.leftScroll').scrollTop($('.rightScroll').scrollTop());
		$('.rightTitleScroll').scrollLeft($('.rightScroll').scrollLeft());
	})

	//模块ID
//	var ModuleID = Y.getUrlParam("ModuleID");
	var ModuleID = 2073;
	//页数
	var page = 1;
	//获取按钮
	commonUtil.loadBtnList(ModuleID,function(){
		$('.btns-container').append('<div style="clear: both;"></div>');
	});
	
	//绑定发货仓库
	commonUtil.bindOdsErpBasStocks({ StockID: 'StockID' }, ['#serarch-warehouse']);
	
	//绑定省市
	var provinceList = [];
	$('#serarch-warehouse').change(function(){
		provinceList = [];
		$('#serarch-province').empty();
		$('#serarch-province').append('<option value="">请选择</option>');
		$('#serarch-city').empty();
		$('#serarch-city').append('<option value="">请选择</option>');
		Y.API2('OdsErpBasArea','GetOdsErpBasAreaList',{
			Param: 2,
			DistrictID: $('#serarch-warehouse').val()
		},function(data){
	    	if(data.Success == false){
	    		swal(data.Message,'','error');
	    	}else{
	    		data.map(function(item){
	    			provinceList.push(item);
	    			$('#serarch-province').append('<option value="'+ item[0].ParentID +'">'+ item[0].ParentName +'</option>');
	    		})
	    	}
	    })
	})
	
	//货品类别
	Y.API3('DWSuppleAllMessage','GetErpSDMatKindList',{},function(data){
    	if(data.Success == false){
    		layer.closeAll('dialog');
    		swal(data.Message,'','error');
    	}else{
    		data.map(function(item){
    			$('#serarch-type').append('<option value="'+ item.KindName +'">'+ item.KindName +'</option>');
    		})
    	}
    })
	
	//货品款型
	Y.API3('DWSuppleAllMessage','GetOdsErpSDMatModel',{},function(data){
    	if(data.Success == false){
    		layer.closeAll('dialog');
    		swal(data.Message,'','error');
    	}else{
    		data.map(function(item){
    			$('#serarch-style').append('<option value="'+ item.ModelName +'">'+ item.ModelName +'</option>');
    		})
    	}
    })
	
	//选择省份
    $('#serarch-province').change(function(){
    	$('#serarch-city').empty();
    	$('#serarch-city').append('<option value="">请选择</option>');
    	var $this = $(this);
    	provinceList.map(function(item){
    		if(item[0].ParentID == $this.val()){
    			item.map(function(city){
    				$('#serarch-city').append('<option value="'+ city.AreaID +'">'+ city.AreaName +'</option>');
    			});
    			$('#serarch-city').val('');
    			return false;
    		}
    	})
    });
    
    //年份
    commonUtil.bindDwGlobalVariables({dictValue: '年份'},['#serarch-year']);
    //季节
    commonUtil.bindDwGlobalVariables({dictValue: '季节'},['#serarch-season']);
    
    //店铺等级
	Y.API2('DwShop','GetShopAndCustBaseInfo',{InfoType: 'ShopLevel'},function(data){
		if(data.Success == false){
			layer.closeAll('dialog');
			swal(data.Message,'','error');
		}else{
			data.map(function(item){
				$('#serarch-level').append('<option value="'+ item.InfoName +'">'+ item.InfoName +'</option>');
			})
		}
	})
	
	//处理表头（批量）
	tableControl.initThead('#batchTable',[{
		trClass: '', children: [
   			{tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllBatch" />', tdId: '', tdClass: '' },
        	{tdText: '尺码', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
        	{tdText: '库存数量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
        	{tdText: '补货占用量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
        	{tdText: '剩余数量', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' }
		]
	}])
	
	//处理表头（左）
	tableControl.initThead('.leftTable',[
		{
			trClass: '', children: [
	   			{tdText: '', c: 0, r: 3, tdHtml: '<span style="display:inline-block; width:24px;"><input type="checkbox" id="checkAll" /></span>', tdId: '', tdClass: 'td-w24 td-h76'},
	        	{tdText: '', c: 0, r: 3, tdHtml: '<span style="display:inline-block; width:62px;">仓库</span>', tdId: '', tdClass: 'td-w62 td-h76'},
	        	{tdText: '', c: 0, r: 3, tdHtml: '<span style="display:inline-block; width:170px;">店铺名称</span>', tdId: '', tdClass: 'td-w170 td-h76'},
	        	{tdText: '', c: 0, r: 3, tdHtml: '<span style="display:inline-block; width:120px;">货号</span>', tdId: '', tdClass: 'td-w120 td-h76'},
	//      	{tdText: '货品简称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w90' },
	//      	{tdText: '款型', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w90' },
	      		{tdText: '', c: 0, r: 3, tdHtml: '<span style="display:inline-block; width:56px;">SKC畅滞销状态</span>', tdId: '', tdClass: 'td-w56' },
	//      	{tdText: '补货间隔', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w62' },
	//          {tdText: '作业+物流天数', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w56' },
	//          {tdText: '销售开始日期', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w72' },
	//          {tdText: '销售结束日期', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w72' },
				{tdText: '', c: 0, r: 3, tdHtml: '<span style="display:inline-block; width:30px;">码段分类</span>', tdId: '', tdClass: 'td-w30 td-h76'},
				{tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:30px;">01</span>', tdId: '', tdClass: 'td-w30 td-h39'},
			]
		},
		{
			trClass: '', children: [
				{tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:30px;">02</span>', tdId: '', tdClass: 'td-w30'},
			]
		},
		{
			trClass: '', children: [
				{tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:30px;">03</span>', tdId: '', tdClass: 'td-w30'},
			]
		},
	])
	
	//处理表头（右）
	var partCount = 4;	//4部分
	var arr01 = ['01','S','M','L','XL','XXL','3XL','4XL','JM','','','',''];					
	var arr02 = ['02','39','40','41','42','43','44','45','','','','',''];									
	var arr03 = ['03','27','28','29','30','31','32','33','34','36','37','38','合计'];
	var children01 = [];
	var children02 = [];
	var children03 = [];
	//fstBorder是为了隔开不同的模块加粗线
	for(var i = 0; i < partCount; i++){
		if(i == 0){
			arr01.map(function(item,j){
				if(j == 0)
					children01.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-noTop-border hide' });
				else
					children01.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' });
			})
			arr02.map(function(item,j){
				var isFst = false;
				if(item == 'S' || item == '39' || item == '27')
					isFst = true;
				if(j == 0)
					children02.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' });
				else
					children02.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: (isFst && i != 0 ? 'fstBorder' : '') });
			})
			arr03.map(function(item,j){
				var isFst = false;
				if(item == 'S' || item == '39' || item == '27')
					isFst = true;
				if(j == 0)
					children03.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' });
				else
					children03.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: (isFst && i != 0 ? 'fstBorder' : '') });
			})
		}else{
			arr01.map(function(item,j){
				if(j != 0){
					var isFst = false;
					if(item == 'S' || item == '39' || item == '27')
						isFst = true;
					
					if(j == 0)
						children01.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' });
					else
						children01.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: (isFst && i != 0 ? 'fstBorder' : '') });
				}
			})
			arr02.map(function(item,j){
				if(j != 0){
					var isFst = false;
					if(item == 'S' || item == '39' || item == '27')
						isFst = true;
						
					if(j == 0)
						children02.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' });
					else
						children02.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: (isFst && i != 0 ? 'fstBorder' : '') });
				}	
			})
			arr03.map(function(item,j){
				if(j != 0){
					var isFst = false;
					if(item == 'S' || item == '39' || item == '27')
						isFst = true;
						
					if(j == 0)
						children03.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' });
					else
						children03.push({tdText: item, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: (isFst && i != 0 ? 'fstBorder' : '') });
				}
			})
		}
	}
	
	tableControl.initThead('.rightTable',[
		{trClass: '', children: [
			{tdText: '码段分类', c: 0, r: 4, tdHtml: '', tdId: '', tdClass: 'td-w28 td-break hide' },
			{tdText: '', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
   			{tdText: '近七天日均销售量', c: 12, r: 0, tdHtml: '', tdId: '', tdClass: '' },
        	{tdText: '补货量', c: 12, r: 0, tdHtml: '', tdId: '', tdClass: 'fstBorder' },
        	{tdText: '在仓库存+在途库存+订单在途', c: 12, r: 0, tdHtml: '', tdId: '', tdClass: 'fstBorder' },
        	{tdText: '补货后', c: 12, r: 0, tdHtml: '', tdId: '', tdClass: 'fstBorder' },
		]},
		{trClass: '', children: children01},
		{trClass: '', children: children02},
		{trClass: '', children: children03},
	])
	
	//无数据处理
	var dealNull = function(){
		var tempChild = [];
		var tempChild2 = [];
		var tempLeftWidth = 0;
		var tempRightWidth = $('.rightTable:first thead tr').eq(1).children().size() * 30;
		$('.leftTableTitle thead tr:first').children().each(function(index){
			if(index != 0)
				tempLeftWidth += $(this).find('span').width();
		})
		tempChild.push({tdText:'', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:23px;"><i class="fa fa-frown-o"></i></span>', tdId: '', tdClass: ''});
		tempChild.push({tdText:'', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:'+ tempLeftWidth +'px">暂无数据</span>', tdId: '', tdClass: 'td-noRight-border'});
		var tempTr = {trClass: '',children: tempChild};
		tableControl.initTbody('.leftTable',[tempTr],0,null);
		tempChild2.push({tdText:' ', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:'+ (tempRightWidth - 6) +'px"></span>', tdId: '', tdClass: ''});
		tempTr = {trClass: '',children: tempChild2};
		tableControl.initTbody('.rightTable',[tempTr],0,null);
		$('.rightScroll tbody td').css({maxWidth: (tempRightWidth - 6) + 'px'});
	}
	dealNull();
	
	//右表格相关数据计算
	var calcRightTb = function(){
		$('#rightList tr').each(function(){
			var $this = $(this);
			//计算第1部分的合计
			var count = 0;
			$($this.find('.td-bg-style1')).each(function(index){
				if(index < $this.find('.td-bg-style1').size() - 1)
					count += (isNaN(parseFloat($(this).text())) ? 0 : parseFloat($(this).text()));
			})
			$this.find('.td-bg-style1:last').text(count.toFixed(2));
			$this.find('.td-bg-style1:last').attr('title',count.toFixed(2));
			//计算第2部分的合计
			count = 0;
			$($this.find('.td-bg-style2')).each(function(index){
				var tempValue = $(this).find('.setnum').size() > 0 ? parseFloat($(this).find('.setnum').val()) : parseFloat($(this).text());
				if(index < $this.find('.td-bg-style2').size() - 1)
					count += (isNaN(tempValue) ? 0 : tempValue);
			})
			$this.find('.td-bg-style2:last').text(count);
			$this.find('.td-bg-style2:last').attr('title',count);
			//计算第3部分的合计
			count = 0;
			$($this.find('.td-bg-style3')).each(function(index){
				if(index < $this.find('.td-bg-style3').size() - 1)
					count += (isNaN(parseFloat($(this).text())) ? 0 : parseFloat($(this).text()));
			})
			$this.find('.td-bg-style3:last').text(count);
			$this.find('.td-bg-style3:last').attr('title',count);
			
			//计算第4部分
			count = 0;
			$($this.find('.td-bg-style4')).each(function(index){
				var tempValue2 = 0;
				if($this.find('.td-bg-style2').eq(index).find('.setnum').size() > 0)
					tempValue2 = parseFloat($this.find('.td-bg-style2').eq(index).find('.setnum').val());
				else
					tempValue2 = parseFloat($this.find('.td-bg-style2').eq(index).text());
				tempValue2 = isNaN(tempValue2) ? 0 : tempValue2;
				var tempValue3 = parseFloat($this.find('.td-bg-style3').eq(index).text());
				tempValue3 = isNaN(tempValue3) ? 0 : tempValue3;
				tempValue4 = tempValue2 + tempValue3;
				if(index == $this.find('.td-bg-style4').size() - 1){
					$(this).text(tempValue4);
				}else{
					$(this).text((isNaN(tempValue4) || tempValue4 == 0 ? '' : tempValue4));
				}
				if(index < $this.find('.td-bg-style4').size() - 1)
					count += (isNaN(parseFloat($(this).text())) ? 0 : parseFloat($(this).text()));
			})
			$this.find('.td-bg-style4:last').text(count);
			$this.find('.td-bg-style4:last').attr('title',count);
			
			//样式整理
			$this.find('.td-bg-style2:first').addClass('fstBorder');
			$this.find('.td-bg-style3:first').addClass('fstBorder');
			$this.find('.td-bg-style4:first').addClass('fstBorder');
		})
	}
	
	//计算批量维护表
	var maintainCount = function(){
		$('#btn-save').removeAttr('disabled');
		$('#batchList tr').each(function(){
		    var $this = $(this);
		    var count = parseInt($this.find('.CanUseQty').text()) - parseInt($this.find('.Taken').text());
		    $this.find('.Remain').text(count);
		    $this.find('.Remain').css({ color: '' });
		    if (count < 0){
		        $this.find('.Remain').css({ color: '#f00' });
		        $('#btn-save').attr('disabled', 'disabled');
		    }
		})
	}
	
	var loadMainList = function(hasArtnum){
		auxiliaryList = [];
		pageAllControl.init('DWSuppleAllMessage','GetNewDWSuppleAllMessageList',{
	    	FHStockID: $('#serarch-warehouse').val(),
	    	ShopKeys: $('#search-store').val().trim(),
	    	ProID: $('#serarch-province').val(),
			CityID: $('#serarch-city').val(),
			ShopLevelCode: $('#serarch-level').val(),
			MaterialID: $('#search-artnum').val().trim(),
			YearNo: $('#serarch-year').val(),
			SeasonName: $('#serarch-season').val(),
			KindName: $('#serarch-type').val(),
			ModelName: $('#serarch-style').val(),
			SuppleQty: $('#serarch-screen').val(),
			Page: page,
			Size: 100,
			needLayer: true,
			alwaysCallBack:function(){
				$('#leftList').empty();
				$('#rightList').empty();
			}
		},function(result){
			page = result.page;
			var tBody1 = [];
			var tBody2 = [];
			if (!Y.checkNull(result.data)) {
				if (result.data.length > 0){
					auxiliaryList = result.data;
					result.data.map(function(item,i){
						//处理左表格
						var tempTr = {
							trClass: '',				
							children: [
								{tdText:'', c:0 , r:0, tdHtml:'<input type="checkbox" class="checkItem" />', tdId:'', tdClass:'td-w24'},
								{tdText: item[0].FHStockName, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-w62'},
								{tdText:'', c:0 , r:0, tdHtml:'<span class="auxiliaryText" data-toggle="modal" data-target="#auxiliary">'+ item[0].ShopName +'</span>', tdId:'', tdClass:'td-w170'},
								{tdText:item[0].MaterialCode, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-w120' + (item[0].isModify ? ' modifyColor' : '')},
//								{tdText:item[0].MaterialShortName, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-w90'},
//								{tdText:item[0].ModelName, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w90'},
								{tdText:item[0].SKCCzpFlag, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w56'},
//								{tdText:item[0].ReplenishDay, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w62'},
//								{tdText:item[0].BTDays, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w56'},
//								{tdText:item[0].SaleBgDate, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w72'},
//								{tdText:item[0].SaleEnddate, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-w72'},
								{tdText:item[0].SizeTypeCode, c:2 , r:0, tdHtml:'', tdId:'', tdClass:'td-w60'},
							]
						};
						tBody1.push(tempTr);
						
						//处理右表格
						var tempChild = [];
						tempChild.push({tdText: item[0].SizeTypeCode, c:2 , r:0, tdHtml:'', tdId:'', tdClass:'hide'});
						
						var rowIndex = 1;
						switch(item[0].SizeTypeCode){
							case '02':
								rowIndex = 2;
								break;
							case '03':
								rowIndex = 3;
								break;
							case '01':
							default:
								break;
						}
								
						$('.rightTable thead tr').eq(rowIndex).children().each(function(index){
							var $this = $(this);
							var count = 0;
							if(index > 0){
								item.map(function(it){
									it.EndQty = Y.checkNull(it.EndQty) ? 0 : it.EndQty;
									it.PathQty = Y.checkNull(it.PathQty) ? 0 : it.PathQty;
									it.OrderPathQty = Y.checkNull(it.OrderPathQty) ? 0 : it.OrderPathQty;
									it.UpdateSuppleQty = Y.checkNull(it.UpdateSuppleQty) ? 0 : it.UpdateSuppleQty;
									//第1部分
									if(it.SizeName == $this.text()&&index<13){
										tempChild.push({tdText: (Y.checkNull(it.AvgWeekSaleQty) ? '' : it.AvgWeekSaleQty.toFixed(2)), c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-bg-style1'});
										return;
									//第2部分
									}else if(it.SizeName == $this.text()&&index>=13&&index<25){
										//是否合计
										if(index != 24){
											//判断是否带货号查询
											if(hasArtnum && $('#batchList tr').size() > 0){
												var countBatch = 0;
												$('#batchList tr').each(function(){
												    if ($(this).find('.SizeName').text().trim() == it.SizeName.trim()) {
												        tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<input type="number" class="setnum ' + it.SizeID + ' ' + $(this).find('.SizeName').text().trim() + '" value="' + (it.UpdateSuppleQty == 0 ? '' : it.UpdateSuppleQty) + '" />', tdId: '', tdClass: 'td-bg-style2  td-bg-style5' });
														return false;
													}
													countBatch++;
												})
												if(countBatch == $('#batchList tr').size())
												    tempChild.push({ tdText: (it.UpdateSuppleQty == 0 ? '' : it.UpdateSuppleQty), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-bg-style2' });
											}else{
											    tempChild.push({ tdText: (it.UpdateSuppleQty == 0 ? '' : it.UpdateSuppleQty), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-bg-style2' });
											}
										}else{
										    tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-bg-style2' });
										}
										return;
									//第3部分
									}else if(it.SizeName == $this.text()&&index>=25&&index<37){
										tempChild.push({tdText: (it.EndQty+it.PathQty+it.OrderPathQty == 0 ? '' : it.EndQty+it.PathQty+it.OrderPathQty), c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-bg-style3'});
										return;
									//第4部分
									}else if(it.SizeName == $this.text()&&index>=37&&index<49){
										tempChild.push({tdText: (it.UpdateSuppleQty+it.EndQty+it.PathQty+it.OrderPathQty == 0 ? '' : it.UpdateSuppleQty+it.EndQty+it.PathQty+it.OrderPathQty), c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-bg-style4'});
										return;
									}
									count++;
								})
								if(count == item.length){
									if(index<13){
										tempChild.push({tdText: '', c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-bg-style1'});
									}else if(index>=13&&index<25){
										//是否合计
										if(index != 24){
											//判断是否带货号查询
											if(hasArtnum && $('#batchList tr').size() > 0){
												var countBatch = 0;
												$('#batchList tr').each(function(){
												    if ($(this).find('.SizeName').text().trim() == $this.text().trim()) {
												        tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<input type="number" class="setnum ' + $(this).find('.hide.SizeID').text().trim() + ' ' + $(this).find('.SizeName').text().trim() + '" value="" />', tdId: '', tdClass: 'td-bg-style2  td-bg-style5' });
														return false;
													}
													countBatch++;
												})
												if(countBatch == $('#batchList tr').size())
												    tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-bg-style2' });
											}else{
											    tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-bg-style2' });
											}
										}else{
										    tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'td-bg-style2' });
										}
									}else if(index>=25&&index<37){
										tempChild.push({tdText: '', c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-bg-style3'});
									}else if(index>=37&&index<49){
										tempChild.push({tdText: '', c:0 , r:0, tdHtml:'', tdId:'', tdClass:'td-bg-style4'});
									}
																			
								}
							}
						})
					
						tempTr = {
							trClass: '',
							children:tempChild
						}
						tBody2.push(tempTr)
					})
					//左表信息处理
					tableControl.initTbody('.leftTable',(tBody1.length > 0 ? tBody1 : null),0,null);
					//右表信息处理
					tableControl.initTbody('.rightTable',(tBody2.length > 0 ? tBody2 : null),0,null);
					calcRightTb();
					
					
				}else{
					//无数据处理
					dealNull();
				}
				changeTableHeight();
			}
		});
		
	}
	
	var auxiliaryList = [];
	var skcList = [];
	var loadList = function(){
		if($('#serarch-warehouse').val() == ''){
			swal('请选择发货仓库');
			return false;
		}
		var tBody3 = [];
		skcList = [];
		$('#batchList').empty();
		//处理SKC列表
		if($('#search-artnum').val().trim() != ''){
			layer.msg('玩命加载中……', {icon: 16, shade: 0.01, time:0, maxWidth:200});
			Y.API2('DWSuppleAllMessage', 'GetDWFHStockCanUseList', {
				FHStockID: $('#serarch-warehouse').val(),
				MaterialID: $('#search-artnum').val().trim(),
		    }, function (data) {
		    	layer.closeAll('dialog');
		    	if(data.Success == false){
					swal(data.Message,'','error');
		    	}else{
		    	    if (data && data.length > 0) {
		    	        skcList = data[0];
		    			data[0].map(function (item) {
							var tempTr = {
								trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),				
								children: [
									{tdText:item.FHStockID, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'hide FHStockID'},
									{ tdText: item.MaterialID, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide MaterialID' },
                                    { tdText: item.SizeID, c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide SizeID ' + item.SizeID },
									{tdText: '', c:0 , r:0, tdHtml:'<input type="checkbox" class="checkBatch" />', tdId:'', tdClass:''},
									{tdText: item.SizeName, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'SizeName'},
									{tdText: item.CanUseQty, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'CanUseQty'},
									{tdText: item.Taken, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'Taken'},
									{tdText: '', c:0 , r:0, tdHtml:'', tdId:'', tdClass:'Remain'},
								]
							};
							tBody3.push(tempTr);
        				})
    					tableControl.initTbody('#batchTable',(tBody3.length > 0 ? tBody3 : null),5,null);
    					maintainCount();
					}
		    		loadMainList(true);
				}
			})
		}else{
			loadMainList(false);
		}
		
	}
	
	//修改补货量
	$('#rightList').on('blur', '.setnum', function () {
	    var trIndex = $(this).parents('tr').index();
		var TempValue = parseInt($(this).val());
		if(!isNaN(TempValue)){
			if(TempValue < 0)
				TempValue = 0;
		}else{
			TempValue = '';
		}
		$(this).val(TempValue);
		calcRightTb();
		var className = $(this).attr('class').split(' ')[1];
		var takenValue = '';
		var auxiliaryValue = 0;
		var inputValue = 0;
		auxiliaryList.map(function (item) {
		    item.map(function (it) {
		        if (it.SizeID == className) {
		            auxiliaryValue += parseInt(it.UpdateSuppleQty);
		        }
		    })
	    })
	    skcList.map(function (item) {
	        if (item.SizeID == className) {
	            takenValue = item.Taken;
	        }
	    })
	    
	    auxiliaryValue = auxiliaryValue == '' ? 0 : auxiliaryValue;
	    $('#rightList tr').each(function () {
	        inputValue += parseInt(Y.checkNull($(this).find('.setnum.' + className).val()) ? 0 : $(this).find('.setnum.' + className).val());
	    })
	    var t = parseInt(auxiliaryValue) - parseInt(inputValue);
		var final = parseInt(takenValue) - parseInt(t);
		var taken = $(".hide.SizeID." + className).parents('tr').find('.Taken').text(final);
		maintainCount();
	})
	
	//查询按钮
	$('.btns-container').on('click','#btn-search',function(){
		page = 1;
		loadList();
	});
	
	//下载按钮
	$(".btns-container").on("click", '#downloadAllocation', function () {
		if($('#serarch-warehouse').val() == ''){
			swal('请选择发货仓库');
			return false;
		}
		
        var conditionsArr = [];
        conditionsArr.push({ column: "sam.FHStockID", value: $('#serarch-warehouse').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "eba.ParentID", value: $('#serarch-province').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "ds.AreaID", value: $('#serarch-city').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "ds.ShopName", value: $('#search-store').val(), operator: "like", connector: "and" });
        conditionsArr.push({ column: "sam.KindName", value: $('#serarch-type').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.YearNo", value: $('#serarch-year').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.SeasonName", value: $('#serarch-season').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.MaterialID", value: $('#search-artnum').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.ModelName", value: $('#serarch-style').val(), operator: "=", connector: "and" });
//      if(parseInt($('#serarch-screen').val()) ==1){
//          conditionsArr.push({ column: "sam.SuppleQty", value: 0, operator: ">", connector: "and" });
//      }else{	
//          conditionsArr.push({ column: "sam.SuppleQty", value: 0, operator: "<=", connector: "and" });
//      }
        conditionsArr.push({ column: "dw.ShopLevelCode", value: $('#serarch-level').val(), operator: "=", connector: "and" });
        conditionsArr = JSON.stringify(conditionsArr);     
//      //如果不是选中的所有尺码，就筛选尺码
//      if ($('#search-size-name').val().length > 0) {
//          conditionsArr.push("SizeName:" + $('#search-size-name').val());
//      }   
        //conditionsArr.push("Page:" + page);
        $.Export({
        	filetype: 'replenishment',
            filename: '智能补货结果',
            conditions: encodeURIComponent(conditionsArr),
            after: function () {
                //回调方法
                //loadList(1);
                swal("导出成功!");
            }
        });
    });
    
    //导出SKC畅滞销状态
    $(".btns-container").on("click", '#downloadSKC', function () {
        var conditionsArr = [];
        conditionsArr.push({ column: "sam.FHStockID", value: $('#serarch-warehouse').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "eba.ParentID", value: $('#serarch-province').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "ds.AreaID", value: $('#serarch-city').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "ds.ShopName", value: $('#search-store').val(), operator: "like", connector: "and" });
        conditionsArr.push({ column: "sam.KindName", value: $('#serarch-type').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.YearNo", value: $('#serarch-year').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.SeasonName", value: $('#serarch-season').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.MaterialID", value: $('#search-artnum').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.ModelName", value: $('#serarch-style').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "dw.ShopLevelCode", value: $('#serarch-level').val(), operator: "=", connector: "and" });
        conditionsArr = JSON.stringify(conditionsArr);     
        $.Export({
        	filetype: 'STATESKC',
            filename: 'SKC畅滞销状态',
            conditions: encodeURIComponent(conditionsArr),
            after: function () {
                //回调方法
                //loadList(1);
                swal("导出成功!");
            }
        });
    });
    
    //导出辅助数据
    $(".btns-container").on("click", '#downloadAuxiliary', function () {
		if($('#serarch-warehouse').val() == ''){
			swal('请选择发货仓库');
			return false;
		}
        var conditionsArr = [];
        conditionsArr.push({ column: "sam.FHStockID", value: $('#serarch-warehouse').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "eba.ParentID", value: $('#serarch-province').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "ds.AreaID", value: $('#serarch-city').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "ds.ShopName", value: $('#search-store').val(), operator: "like", connector: "and" });
        conditionsArr.push({ column: "sam.KindName", value: $('#serarch-type').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.YearNo", value: $('#serarch-year').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.SeasonName", value: $('#serarch-season').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.MaterialID", value: $('#search-artnum').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "sam.ModelName", value: $('#serarch-style').val(), operator: "=", connector: "and" });
        conditionsArr.push({ column: "dw.ShopLevelCode", value: $('#serarch-level').val(), operator: "=", connector: "and" });
        if(parseInt($('#serarch-screen').val()) ==1){
        	conditionsArr.push({ column: "sam.UpdateSuppleQty", value: 0, operator: ">", connector: "and" });
        }else if(parseInt($('#serarch-screen').val()) ==0){ 	
            conditionsArr.push({ column: "sam.SuppleQty", value: 0, operator: ">", connector: "and" });
        }
        conditionsArr = JSON.stringify(conditionsArr);     
        $.Export({
        	filetype: 'SECONDARYDATA',
            filename: '辅助数据',
            conditions: encodeURIComponent(conditionsArr),
            after: function () {
                //回调方法
                //loadList(1);
                swal("导出成功!");
            }
        });
    });
    
    
    //弹出辅助信息
    $('#leftList').on('click','.auxiliaryText',function(){
    	var tr = $(this).parents('tr');
    	var index = tr.index();
    	$('#auxiliaryList').empty();
    	var tBody = [];
		layer.msg('玩命加载中……', {icon: 16, shade: 0.01, time:0, maxWidth:200});
    	Y.API2('DWSuppleAllMessage','GetDWAuxiliaryInformationList',{
    		FHStockID: auxiliaryList[index][0]['FHStockID'],
    		ShopCode: auxiliaryList[index][0]['ShopCode'],
    		MaterialID: auxiliaryList[index][0]['MaterialID'],
    	},function(data){
    		layer.closeAll('dialog');
    		if(data.Success == false){
    			swal(data.Message,'','error');
    		}else{
    			data.map(function(item,i){
    				var tempTr = {
						trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),
						children: [
							{tdText: (item.ShopName || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.MaterialCode || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.SizeName || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.TotalSaleQty || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.TotalMoveQty || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.WeekSaleQty || 0), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.WeekMoveQty || 0), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.FirstArriveDate || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.SaleDays || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.CalcSaleRate || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.CZPFlag || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.PeriodSuppleRate || ''), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.SizeCoreFlag == 0 ? '否' : '是'), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.DisPlayQty || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.HopeQty || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.ResultQty || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
							{tdText: (item.SuppleQty || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
						]
					};
					tBody.push(tempTr);
    			})
    		}
    		tableControl.initTbody('#auxiliaryTable',(tBody.length > 0 ? tBody : null),16,null);
    	})		
    })
    
    //全选批量维护补货量
    $('#batchTable').on('click','#checkAllBatch',function(){
    	if(this.checked)
			$('#batchTable .checkBatch').each(function(){this.checked=true;});
		else
			$('#batchTable .checkBatch').each(function(){this.checked=false;});
    })
    //选择批量维护补货量
    $('#batchTable').on('click','.checkBatch',function(){
		if($('#batchTable .checkBatch').size() == $('#batchTable .checkBatch:checked').size())
			$('#batchTable #checkAllBatch').prop("checked", true);
		else
			$('#batchTable #checkAllBatch').prop("checked", false);
	});
    
    //全选仓库店铺信息
    $('.leftTable').on('click','#checkAll',function(){
    	if(this.checked)
			$('.leftTable .checkItem').each(function(){this.checked=true;});
		else
			$('.leftTable .checkItem').each(function(){this.checked=false;});
    })
    //选择批量维护补货量
    $('.leftTable').on('click','.checkItem',function(){
		if($('.leftTable .checkItem').size() == $('.leftTable .checkItem:checked').size())
			$('.leftTable #checkAll').prop("checked", true);
		else
			$('.leftTable #checkAll').prop("checked", false);
	});
    
    //应用按钮
    $('#application').click(function(){
    	var coefficient = parseFloat($('.coefficient').val().trim());
    	if(isNaN(coefficient))
    		return false;
    	if($('#batchList .checkBatch:checked').size() == 0){
    		swal('请选择尺码');
    		return false;
    	}
    	$('#batchList .checkBatch:checked').each(function(){
    		var $this = $(this);
    		var tr = $this.parents('tr');
    		var sizeID = tr.find('.SizeID').text();
    		$('.leftTable .checkItem:checked').each(function(){
    			var trIndex = $(this).parents('tr').index();
    			var rTr = $('#rightList tr').eq(trIndex);
    			var rV = rTr.find('.setnum.' + sizeID);
    			if(rV.val() != ''){
    				rV.val( Math.ceil( parseInt(rV.val()) * coefficient ) );
    				rV.blur();
    			}
    		})
    	})
    })
    
    //保存信息
    $('.btns-container').on('click','#btn-save',function(){
    	if($('#batchList').children().size() == 0){
    		swal('请输入货号获取SKC信息，再进行保存');
    		return false;
    	}
    	if($('#leftList .checkItem:checked').size() == 0){
    		swal('请选择要保存的信息');
    		return false;
    	}

    	var submitList = [];
    	$('#leftList .checkItem:checked').each(function(){
    		var $this = $(this);
    		var leftTr = $this.parents('tr');
    		var rightTr = $('#rightList tr').eq(leftTr.index());
    		rightTr.find('.setnum').each(function(){
    		    var auxiliaryItem = auxiliaryList[leftTr.index()][0];
    			if(!isNaN(parseInt($(this).val()))){
    				submitList.push({
	    				FHStockID: auxiliaryItem.FHStockID,
	    				ShopCode: auxiliaryItem.ShopCode,
	    				MaterialID: auxiliaryItem.MaterialID,
	    				StockDate: auxiliaryItem.StockDate,
	    				SizeTypeCode: auxiliaryItem.SizeTypeCode,
	    				SizeName: $(this).attr('class').split(' ')[2],
	    				SizeID: $(this).attr('class').split(' ')[1],
	    				UpdateSuppleQty: $(this).val()
	    			})
    			}
    		})
    	});
//  	console.log(submitList);
    	
  	    layer.msg('玩命加载中……', {icon: 16, shade: 0.01, time:0, maxWidth:200});
  	    Y.API2('DWSuppleAllMessage','ModifyDWSuppleAllMessage',{
  		    list: submitList,
  	    },function(data){
  		    layer.closeAll('dialog');
  		    if(data.Success == false){
  			    swal(data.Message,'','error');
  		    }else{
  		        swal('保存成功', '', 'success');
  		    }
  	    })
    })
})
</script>
</asp:Content>

